﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Reflection;
using System.Drawing;
using DailyPhoto.Common;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Bson.Serialization;
using Newtonsoft.Json;

namespace DailyPhoto.Entities
{
    static class Repositories
    {

        static Repositories()
        {
            
            AllMap = new Dictionary<string, IRepository>();

            foreach (var s in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (s.IsInterface)
                    continue;

                if (s.GetInterface(typeof(IRepository).Name) != null)
                {
                    var m = Activator.CreateInstance(s) as IRepository;
                    AllMap[m.Name] = m;
                }
            }
        }


        public static IRepository Get(string name) { return AllMap[name]; }

        public static IEnumerable<IRepository> All { get { return AllMap.Values; } }

        private static Dictionary<string, IRepository> AllMap { get; set; }
    }


    public interface IRepository
    {
        string Name { get; }
        IEnumerable<Photo> Fetch();
    }

}
